<template>
	<view class="code_input">
		<view class="close" @click="close">
			<image src="@/static/images/close.png"></image>
		</view>
		<view class="header">{{$t('home.购买')}}</view>
		<view class="info_view">
			<image :src="data_info.product_cover" class="cover"></image>
			<view class="info_box">
				<view class="name">{{data_info.product_name}}</view>
				<view class="number">#{{data_info.product_number}}</view>
				<view class="price">
					<text class="unit">$</text>
					<text class="value">{{data_info.price}}</text>
				</view>
			</view>
		</view>
		<view class="title">{{$t('market.交易密码')}}</view>
		<view class="code_view">
			<uv-code-input mode="box" color="#fff" dot @finish="finish"></uv-code-input>
		</view>
		<view class="desc">
			<image src="@/static/images/checked.png"></image>
			<view>
				{{$t('market.协议')}}
				<!-- <text>我已同意并遵守平台</text>
				<text>《商品购买和转售须知》</text> -->
			</view>
		</view>
		<view class="submit" @click="submit">
			<view>{{$t('home.购买')}}</view>
		</view>
	</view>
</template>

<script setup>
	import {
		ref,
		onUnmounted
	} from "vue";
	const props = defineProps({
		data: Object
	});
	const data_info = ref(props.data);

	const emit = defineEmits(["close", "submit"]);
	const close = () => emit("close");
	let value;
	const finish = (e) => value = e;
	const submit = () => emit("submit", value);
	onUnmounted(() => value = null);
</script>

<style scoped lang="scss">
	.code_input {
		padding: 30rpx 20rpx;
		box-sizing: border-box;
		background: #2F2F2F;
		position: relative;

		.close {
			position: absolute;
			right: 30rpx;
			top: 20rpx;
			z-index: 2;

			image {
				width: 44rpx;
				height: 44rpx;
			}
		}

		.header {
			color: #FFFFFF;
			font-size: 40rpx;
			font-weight: bold;
			padding-left: 10rpx;
			padding-bottom: 50rpx;
			box-sizing: border-box;
		}

		.info_view {
			height: 240rpx;
			border-radius: 20rpx;
			padding: 20rpx;
			box-sizing: border-box;
			background: #2B2B2B;
			display: flex;
			align-items: center;

			.cover {
				width: 200rpx;
				height: 200rpx;
			}

			.info_box {
				flex: 1;
				min-height: 200rpx;
				padding: 18rpx 0 26rpx 30rpx;
				box-sizing: border-box;

				.name {
					color: #FFFFFF;
					font-size: 32rpx;
					font-weight: 800;
				}

				.number {
					color: #999999;
					font-size: 32rpx;
					font-weight: 800;
					margin-top: 30rpx;
					margin-bottom: 40rpx;
				}

				.price {
					color: #DDF247;

					.unit {
						font-size: 20rpx;
						font-weight: bold;
					}

					.value {
						font-size: 36rpx;
						font-family: DINPro;
					}
				}
			}
		}

		.title {
			color: #CCCCCC;
			font-size: 32rpx;
			font-weight: bold;
			margin-top: 40rpx;
			margin-bottom: 30rpx;
			padding-left: 30rpx;
			box-sizing: border-box;
			position: relative;

			&::after {
				content: "";
				width: 5rpx;
				height: 32rpx;
				background: #DDF247;
				position: absolute;
				left: 10rpx;
				top: 50%;
				transform: translateY(-50%);
				z-index: 2;
			}
		}

		.code_view {
			display: flex;
			justify-content: center;
		}

		.desc {
			padding: 52rpx 0 52rpx 18rpx;
			box-sizing: border-box;
			display: flex;
			align-items: center;

			image {
				width: 40rpx;
				height: 40rpx;
			}

			view {
				flex: 1;
				color: #999999;
				font-size: 26rpx;
				padding-left: 12rpx;
				box-sizing: border-box;
			}
		}

		.submit {
			padding: 0 45rpx;
			box-sizing: border-box;

			view {
				height: 88rpx;
				line-height: 88rpx;
				text-align: center;
				color: #111111;
				font-size: 28rpx;
				font-weight: bold;
				border-radius: 20rpx;
				background: #DDF247;
			}
		}
	}
</style>